//
//  ViewController.m
//  UIphotoView
//
//  Created by mac on 15-12-22.
//  Copyright (c) 2015年 yb. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
{
    UIScrollView *scroll;
    UIPageControl * page;
    
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.title = @"图片の滑动";
    //隐藏标题栏
    //self.navigationController.hidesBarsOnTap = Yes;
    
    //图片的边框
    scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:scroll];
    //定义数组存放照片
    NSArray *arr = [[NSBundle mainBundle] URLsForResourcesWithExtension:@"jpeg" subdirectory:nil];
    [arr enumerateObjectsUsingBlock:^(NSURL *obj, NSUInteger idx, BOOL *stop) {
        UIImage *img = [UIImage imageNamed:obj.lastPathComponent];
        CGRect rect = self.view.bounds;
        rect.origin.x = idx * rect.size.width;
        UIImageView * iv = [[UIImageView alloc]initWithFrame:rect];
        iv.image = img;
        [scroll addSubview:iv];
    }];
    //滑动
    scroll.contentSize = CGSizeMake(self.view.frame.size.width * arr.count, self.view.frame.size.height);
    scroll.pagingEnabled = YES;
    //scroll.alwaysBounceHorizontal = NO;
    scroll.directionalLockEnabled = YES;
    scroll.delegate = self;
    
    page = [[UIPageControl alloc]initWithFrame:CGRectZero];
    page.numberOfPages = 11;
    [page sizeToFit];
    page.center = CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height - 100);
    [self.view addSubview:page];
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"engding !!!  %f",scrollView.contentOffset.x);
    CGFloat loat = scrollView.contentOffset.x / self.view.frame.size.width;
    page.currentPage = (int)loat;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
